"use strict";

var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

require('babel-polyfill');
var path = require("path");
var express = require("express");
var config = require("./config.js");
var PROCESSING = require("./readConfig.js");
var Insert = require("./insertConfig.js");
var qiniu = require("./qiniu/index.js");
var cors = require('cors');

var app = express();
var multer = require("multer");

var bodyParser = require('body-parser');
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(multer());

//网站首页
app.post("/", function (req, res, next) {
    let dataFn = req.body.ct + '_' + req.body.ac;
    console.log(dataFn);
    //读取---
    if (typeof PROCESSING[dataFn] == "function") {
        //读取
        PROCESSING[dataFn](req.body, res, next);
    } else if (typeof Insert[dataFn] == "function") {
        console.log("纯属？");
        //存储
        return Insert[dataFn](req.body, res, next);
    } else {
        console.log("不是一个函数", dataFn);
    }
});
//浏览器测试
//http://127.0.0.1:3000/?pf=2&from_id=&ct=comment&ac=comment_list&doc_id=1&shequ_id=1&page=1
app.get("/", function (req, res, next) {
    let dataFn = req.query.ct + '_' + req.query.ac;
    if (typeof PROCESSING[dataFn] == "function") {
        PROCESSING[dataFn](req.query, res, next);
    } else {
        console.log("不是一个函数", dataFn);
    }
});
app.get("/token", function (req, res, next) {
    console.log("秘钥" + qiniu.token);

    res.send({ token: qiniu.token });
});
app.get("/folder", (req, res, next) => {
    let foo = (() => {
        var _ref = (0, _asyncToGenerator3.default)(function* () {});

        return function foo() {
            return _ref.apply(this, arguments);
        };
    })();

    res.send({ fileInfro: "100" });
});

app.listen(config.port);
console.log("服务器已经启动:http://127.0.0.1:3000");